﻿// Write a program that reads two numbers N and K and generates all the combinations of K distinct elements from the set [1..N].
// Example:	N = 5, K = 2 -> {1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 3}, {2, 4}, {2, 5}, {3, 4}, {3, 5}, {4, 5}

using System;

class CombinationOfKDistinctElements
{
    static void Main()
    {
        uint numberN;
        do
        {
            Console.Write("Enter number N: ");
        } while (!uint.TryParse(Console.ReadLine(), out numberN));

        uint numberK;
        do
        {
            Console.Write("Enter number K: ");
        } while (!uint.TryParse(Console.ReadLine(), out numberK));

        uint[] combinationsArray = new uint[numberK];
        GetCombination(combinationsArray, numberN, 0, 1);
    }

    private static void GetCombination(uint[] combinationsArray, uint numberN, uint index, uint currentNumber)
    {
        if (index == combinationsArray.Length)
        {
            PrintArray(combinationsArray);
        }
        else
        {
            for (uint i = currentNumber; i <= numberN; i++)
            {
                combinationsArray[index] = i;
                GetCombination(combinationsArray, numberN, index + 1, i + 1);
            }
        }
    }

    private static void PrintArray(uint[] array)
    {
        Console.Write("{");
        for (uint i = 0; i < array.Length; i++)
        {
            Console.Write(array[i]);
            if (i != array.Length - 1)
            {
                Console.Write(", ");
            }
        }
        Console.WriteLine("}");
    }
}